package com.topisv.tms.mybatis;

import java.io.Serializable;
import java.util.List;
/**
 * mybatis翻页对象
 * @author Fisher
 * @version 1.0.0
 */

public class Pagination implements Serializable {
    private static final long serialVersionUID = -2941676918809439314L;
    
    private int          iTotalRecords = 0;
    private int          iTotalDisplayRecords = 0;
    private List<Object> aaData;
    private RowBoundsExt    rowBounds;
    
    public Pagination(RowBoundsExt rowBounds, int total) {
        this.rowBounds = new RowBoundsExt(rowBounds.getOffset(), rowBounds.getLimit());
        this.iTotalRecords = total;
        this.iTotalDisplayRecords = total;
    }
    
    public Pagination(RowBoundsExt rowBounds, int total, List<Object> data) {
        this.rowBounds = new RowBoundsExt(rowBounds.getOffset(), rowBounds.getLimit());
        this.iTotalRecords = total;
        this.iTotalDisplayRecords = total;
        setAaData(data);
    }
    
    public RowBoundsExt getRowBounds() {
        return new RowBoundsExt(this.rowBounds.getOffset(), this.rowBounds.getLimit());
    }
    
    public List<Object> getAaData() {
        return this.aaData;
    }
    
    public void setAaData(List<Object> aaData) {
        this.aaData = aaData;
        if ((aaData != null) && (aaData.size() > this.iTotalRecords));
            //TODO
            //throw new BusinessException(MsgType.WARN.getFlag(), "data.size>total.please check total.");
    }
    
    public int getiTotalRecords() {
        return iTotalRecords;
    }

    
    public void setiTotalRecords(int iTotalRecords) {
        this.iTotalRecords = iTotalRecords;
    }

    
    public int getiTotalDisplayRecords() {
        return iTotalDisplayRecords;
    }

    
    public void setiTotalDisplayRecords(int iTotalDisplayRecords) {
        this.iTotalDisplayRecords = iTotalDisplayRecords;
    }

    public int getTotal() {
        return this.iTotalRecords;
    }
    
    public int getPageTotal() {
        int size = this.rowBounds.getLimit();
        return (int) Math.ceil(this.iTotalRecords * 1.0D / size);
    }
}
